#!/usr/bin/env python
# -*- encoding: UTF-8 -*-
from __future__ import print_function

from flask import url_for,request
from flask_restful import Resource

from . import api
from . import camManger,Cam
from .. import myprint
from . import flag

@api.resource("/api/calibrate_camera/<int:cam_id>")
class calibrate_camera(Resource):
    def get(self,cam_id):
        cam = camManger.get(cam_id=cam_id)
        if "w" in request.values and "h" in request.values:
            w = int(request.values['w'])
            h = int(request.values['h'])
        else:
            w, h = 12, 9
        cam.calibration(w=w,h=h,unit=2) # 标定板的参数

@api.resource("/api/save/camera/<int:cam_id>")
class save_image(Resource):
    def get(self,cam_id):
        video = camManger.get_video(cam_id)
        if "image_flag" in request.values:
            image_flag = request.values["image_flag"]
        else:
            image_flag = flag.image.collect
        video.save_image(image_flag)